/*
 *    Copyright 2010-2013 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package com.google.code.jbauble.db;

import com.google.code.jbauble.db.exception.DataAccessException;

/**
 * 数据访问接口
 * @author Scott Hernandez
 * @author Drizzt
 *
 */
public interface Datastore {	
	/** 通过Query对象删除数据  */
	<T> int delete(Query<T> q);
	/** 通过对象删除数据 */
	<T> int delete(T entity);

	/** 查询返回所有数据 */
	<T> Query<T> find(Class<T> clazz);

	/** 
	 * <p>
	 * Find all instances by collectionName, and filter property.
	 * </p><p>
	 * This is the same as: {@code find(clazzOrEntity).filter(property, value); }
	 * </p>
	 */
	<T, V> Query<T> find(Class<T> clazz, String property, V value);
	
	/** 
	 * <p>
	 * Find all instances by collectionName, and filter property.
	 * </p><p>
	 * This is the same as: {@code find(clazzOrEntity).filter(property, value).offset(offset).limit(size); }
	 * </p>
	 */
	<T,V> Query<T> find(Class<T> clazz, String property, V value, int offset, int size);
	/** Saves the entities (Objects) and updates the @Id field */
	<T> Iterable<Key<T>> save(Iterable<T> entities);
	/** Saves the entities (Objects) and updates the @Id field */
	<T> Iterable<Key<T>> save(T... entities);
	/** Saves the entity (Object) and updates the @Id field */
	<T> Key<T> save(T entity);
	/** Returns a new query bound to the kind (a specific {@link DBCollection})  */
	<T> Query<T> createQuery(Class<T> kind);
	
	/** 插入一条数据 */
	<T> Key<T> insert(T t) throws DataAccessException;
	
	/** 更新一条数据 */
	<T> int update(T t) throws DataAccessException;
	
	/** 返回sql操作对象 */
	SqlNative getSqlNative();
}